import {createRouter as _createRouter, createWebHistory, createMemoryHistory} from 'vue-router'

const pages = import.meta.glob("./views/*.vue")
const routes = Object.keys(pages).map((path) => {
	const name = path.match(/\.\/views(.*)\.vue$/)[1].toLowerCase()
	if(name == "/category"){
		return {
			path: name+"/:name",
			component: pages[path],
			meta: {
				title: ''
			},
		}
	}else if(name == "/home"){
		return {
			path: "/",
			component: pages[path],
			meta: {
				title:"首页"
			},
		}
	}else{
		return {
			path: name,
			component: pages[path], // () => import('./pages/*.vue')
			meta: {
				title:"博客"
			},
		}
	}
})

export function createRouter(){
	const routerHistory = import.meta.env.SSR ? createMemoryHistory() : createWebHistory();
	// history: createWebHashHistory('/'),//采用hash 模式
	// history: createWebHistory(), //采用 history 模式
    return _createRouter({
		history: routerHistory, //采用 history 模式
		routes,
	})
}
